<?php
namespace app\admin\controller;

use app\Basic;
use app\Logined;
use \think\facade\Db;

class User extends Logined
{
    public function edit_password()
    {
        Db::name('user')->where('user_id',$this->user_id)->update([
            'password' => $this->param['password'],
            'update_time' => time(),
        ]);
        Db::name('token')->where('token_user_id',$this->user_id)->delete();
        return $this->success('修改密码成功！');
    }

    public function permissions()
    {
        $permission_ids = Db::name('role')->where('role_id',$this->user_info['role_id'])->value('permission_ids');
        $permission_ids = json_decode($permission_ids,true);
        if($this->user_info['role_id']==1){//超级管理员
            $permissions = Db::name('permission')->select();
            return $this->success('请求成功！',['permissions'=>$permissions]);
        }
        if(empty($permission_ids)){ // 空权限
            return $this->success('请求成功！',['permissions'=>[]]);
        }
        $permissions = Db::name('permission')->where('permission_id','in',$permission_ids)->order('sort_num','desc')->select();
        return $this->success('请求成功！',['permissions'=>$permissions]);
    }
    public function user_info()
    {
        return $this->success('请求成功！',['user_info'=>$this->user_info]);
    }


}
